package cn.zzuisa.bluebox.base.facade;

import io.swagger.annotations.ApiModelProperty;
/**
 * 返回值
 * @author Ao
 *
 * @param <T>
 */
public class R<T> {

	public static final int SUCCESS = 20000;
	public static final int UNLOGIN = 1;
	public static final int UNAUTHORIZED = 2;
	public static final int ERROR = 3;

	public static final int UNBINDING = 4;

	@ApiModelProperty(value = "返回码", required = true)
	private Integer code;
	@ApiModelProperty(value = "返回值包装", required = true)
	private T data;

	/**
	 * 通用错误code时调用
	 * @param data
	 * @return
	 */
	public static <Y> R<Y> error(Y data) {
		R<Y> r = new R<Y>(ERROR);
		r.setData(data);
		return r;
	}
	/**
	 * 未登录
	 * @param data
	 * @return
	 */
	public static <Y> R<Y> unLogin(Y data) {
		R<Y> r = new R<Y>(UNLOGIN);
		r.setData(data);
		return r;
	}
	/**
	 * 未绑定
	 * @param data
	 * @return
	 */
	public static <Y> R<Y> unBinding(Y data) {
		R<Y> r = new R<Y>(UNBINDING);
		r.setData(data);
		return r;
	}
	/**
	 * 无权限
	 */
	public static <Y> R<Y> unAuthorized(Y data) {
		R<Y> r = new R<Y>(UNAUTHORIZED);
		r.setData(data);
		return r;
	}
	/**
	 * 成功时调用
	 * @param data
	 * @return
	 */
	public static <Y> R<Y> ok(Y data) {
		R<Y> r = new R<Y>(SUCCESS);
		r.setData(data);
		return r;
	}

	/*分界线：以下为构造函数和getter、setter*/

	public R(Integer code, T data) {
		this.code = code;
		this.data = data;
	}

	public R(Integer code) {
		this.code = code;
	}

	public Integer getCode() {
		return code;
	}

	public void setCode(Integer code) {
		this.code = code;
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}

}
